package org.fuxia.im.core.client;

import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import org.fuxia.im.core.AbstractContext;

@Deprecated
public class ClientApplicationContext extends AbstractContext
{
	private static ClientApplicationContext	instance;
	private static final String				configFile	= "org/fuxia/im/core/config.properties";
	private final Properties				configProps;

	private static byte[]					lock		= new byte[1];

	private void initContext()
	{
		Iterator<Object> keyIter = configProps.keySet().iterator();
		while (keyIter.hasNext())
		{
			String key = keyIter.next().toString();
			this.put(key, configProps.get(key));
		}
	}

	private ClientApplicationContext()
	{
		context = new ConcurrentHashMap<Object, Object>();

		configProps = new Properties();
		try
		{
			configProps.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile));
		}
		catch (IOException e)
		{
			e.printStackTrace();
			System.exit(1);
			//log 
		}
		initContext();
	}

	public static ClientApplicationContext getContext()
	{
		synchronized (lock)
		{
			if (instance == null)
			{
				instance = new ClientApplicationContext();
			}
		}

		return instance;
	}

}
